package cn.gson.springboot.model.pojos;

import javax.persistence.*;
import java.sql.Date;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "storage_", schema = "crm")
public class Storage {
    private int storageId;
    private String storageTheme;// 入库主题
    private Date storageDate;// 入库填单时间
    private Integer storageStatus;// 入库状态
    private String storageNote;// 入库备注
    private Date storageExecutorDate;// 入库执行时间
    private Warehouse warehouseByWarehouseId;// 入库仓库
    private Employee employeeByStoEmployeeId;// 入库填单人
    private Employee employeeByAffEmployeeId;// 入库确认人
    private Purchase purchaseByPurchaseId;// 对应采购单
    private Return returnByReturnId;// 对应退货单
    private Customer customerByCustomerId;// 对应供应商
    private List<StorageDetail> storageDetailsByStorageId;

    @Id
    @Column(name = "storage_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY,generator = "seq")
    public int getStorageId() {
        return storageId;
    }

    public void setStorageId(int storageId) {
        this.storageId = storageId;
    }



    @Basic
    @Column(name = "storage_theme", nullable = true, length = 255)
    public String getStorageTheme() {
        return storageTheme;
    }

    public void setStorageTheme(String storageTheme) {
        this.storageTheme = storageTheme;
    }

    @Basic
    @Column(name = "storage_date", nullable = true)
    public Date getStorageDate() {
        return storageDate;
    }

    public void setStorageDate(Date storageDate) {
        this.storageDate = storageDate;
    }

    @Basic
    @Column(name = "storage_status", nullable = true)
    public Integer getStorageStatus() {
        return storageStatus;
    }

    public void setStorageStatus(Integer storageStatus) {
        this.storageStatus = storageStatus;
    }

    @Basic
    @Column(name = "storage_note", nullable = true, length = 255)
    public String getStorageNote() {
        return storageNote;
    }

    public void setStorageNote(String storageNote) {
        this.storageNote = storageNote;
    }

    @Basic
    @Column(name = "storage_executor_date", nullable = true, length = 255)
    public Date getStorageExecutorDate() {
        return storageExecutorDate;
    }

    public void setStorageExecutorDate(Date storageExecutorDate) {
        this.storageExecutorDate = storageExecutorDate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Storage storage = (Storage) o;
        return storageId == storage.storageId &&
                Objects.equals(storageTheme, storage.storageTheme) &&
                Objects.equals(storageDate, storage.storageDate) &&
                Objects.equals(storageStatus, storage.storageStatus) &&
                Objects.equals(storageNote, storage.storageNote) &&
                Objects.equals(storageExecutorDate, storage.storageExecutorDate);
    }

    @Override
    public int hashCode() {
        return Objects.hash(storageId, storageTheme, storageDate, storageStatus, storageNote, storageExecutorDate);
    }

    @ManyToOne
    @JoinColumn(name = "warehouse_id", referencedColumnName = "warehouse_id")
    public Warehouse getWarehouseByWarehouseId() {
        return warehouseByWarehouseId;
    }

    public void setWarehouseByWarehouseId(Warehouse warehouseByWarehouseId) {
        this.warehouseByWarehouseId = warehouseByWarehouseId;
    }

    @ManyToOne
    @JoinColumn(name = "purchase_id", referencedColumnName = "purchase_id")
    public Purchase getPurchaseByPurchaseId() {
        return purchaseByPurchaseId;
    }

    public void setPurchaseByPurchaseId(Purchase purchaseByPurchaseId) {
        this.purchaseByPurchaseId = purchaseByPurchaseId;
    }

    @ManyToOne
    @JoinColumn(name = "customer_id", referencedColumnName = "customer_id")
    public Customer getCustomerByCustomerId() {
        return customerByCustomerId;
    }

    public void setCustomerByCustomerId(Customer customerByCustomerId) {
        this.customerByCustomerId = customerByCustomerId;
    }

    @ManyToOne
    @JoinColumn(name = "sto_emp_id", referencedColumnName = "emp_id")
    public Employee getEmployeeByStoEmployeeId() {
        return employeeByStoEmployeeId;
    }

    public void setEmployeeByStoEmployeeId(Employee employeeByStoEmployeeId) {
        this.employeeByStoEmployeeId = employeeByStoEmployeeId;
    }

    @ManyToOne
    @JoinColumn(name = "aff_emp_id", referencedColumnName = "emp_id")
    public Employee getEmployeeByAffEmployeeId() {
        return employeeByAffEmployeeId;
    }

    public void setEmployeeByAffEmployeeId(Employee employeeByAffEmployeeId) {
        this.employeeByAffEmployeeId = employeeByAffEmployeeId;
    }

    @ManyToOne
    @JoinColumn(name = "return_id", referencedColumnName = "return_id")
    public Return getReturnByReturnId() {
        return returnByReturnId;
    }

    public void setReturnByReturnId(Return returnByReturnId) {
        this.returnByReturnId = returnByReturnId;
    }

    @OneToMany(mappedBy = "storageByStorageId",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    public List<StorageDetail> getStorageDetailsByStorageId() {
        return storageDetailsByStorageId;
    }

    public void setStorageDetailsByStorageId(List<StorageDetail> storageDetailsByStorageId) {
        this.storageDetailsByStorageId = storageDetailsByStorageId;
    }
}
